const pool = require('../config/db');
const { v4: uuidv4 } = require('uuid');

const Like = {
  async create({ user_id, post_id }) {
    const like_id = uuidv4();
    await pool.query('INSERT INTO likes (like_id, user_id, post_id) VALUES (?, ?, ?)', [like_id, user_id, post_id]);
    return { like_id };
  },

  async delete(user_id, post_id) {
    await pool.query('DELETE FROM likes WHERE user_id = ? AND post_id = ?', [user_id, post_id]);
  },

  async exists(user_id, post_id) {
    const [rows] = await pool.query('SELECT 1 FROM likes WHERE user_id = ? AND post_id = ?', [user_id, post_id]);
    return rows.length > 0;
  }
};

module.exports = Like;